import express from "express";
import Data from "../MockData/MockData.js";

const queryDataList = express.Router();
// const db = require('../../mysql/db')
let dataRes = [];
function query(page, pageSize) {
    let data = Data;
    let total = data.length;
    let start = (page - 1) * pageSize;
    let end = page * pageSize;
    dataRes = data.slice(start, end);
    return {
        list: dataRes,
        total: total,
    };
}

queryDataList.post("/dataList", (req, res) => {
    console.log(req.body);
    const page = req.body.page;
    const pageSize = req.body.pageSize;
    const dataRes = query(page, pageSize);
    res.send({
        code: 200, // 0 表示处理成功，1 表示处理失败
        message: "数据信息查看成功！", // 状态的描述
        data: dataRes, // 需要响应给客户端的数据
    });
});
export default queryDataList;
